package com.example.myapplication.activity;

import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import androidx.fragment.app.Fragment;

import com.example.myapplication.BaseActivity;
import com.example.myapplication.BaseFgm;
import com.example.myapplication.R;
import com.example.myapplication.fragment.MineFgm;
import com.example.myapplication.fragment.NotifyFgm;
import com.example.myapplication.fragment.SquareFgm;
import com.example.myapplication.util.ToastUtil;
import com.example.myapplication.window.ChooseCameraPop;
import com.example.myapplication.window.ChoosePubPop;

public class HomeAty extends BaseActivity {
    private RadioGroup rgBottom;
    private BaseFgm mineFragment, notifyFgm,squareFgm;
    private View btAdd;
    @Override
    protected void logicStart() {
        ((RadioButton) rgBottom.getChildAt(0)).setChecked(true);
    }

    @Override
    protected void initView() {
        rgBottom = findViewById(R.id.rgBottom);
        btAdd=findViewById(R.id.btAdd);

        mineFragment = new MineFgm();
        notifyFgm = new NotifyFgm();
        squareFgm=new SquareFgm();
        getSupportFragmentManager().beginTransaction().add(R.id.rp, mineFragment).add(R.id.rp, notifyFgm).add(R.id.rp,squareFgm).commitAllowingStateLoss();
    }

    @Override
    protected void setListener() {
        super.setListener();
        rgBottom.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                View viewById = rgBottom.findViewById(checkedId);
                if (viewById instanceof RadioButton) {
                    switch (((RadioButton) viewById).getText().toString()) {
                        case "广场":
                            getSupportFragmentManager().beginTransaction().show(squareFgm).hide(notifyFgm).hide(mineFragment).commitAllowingStateLoss();

                            break;

                        case "会玩":

                            break;

                        case "通知":
                            getSupportFragmentManager().beginTransaction().show(notifyFgm).hide(mineFragment).hide(squareFgm).commitAllowingStateLoss();

                            break;

                        case "我的":
                            getSupportFragmentManager().beginTransaction()
                                    .show(mineFragment).hide(notifyFgm).hide(squareFgm).commitAllowingStateLoss();
                            break;
                        default:
                            break;
                    }
                }
            }
        });
        btAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                new ChoosePubPop(HomeAty.this).showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM,0,0);

            }
        });
    }



    @Override
    public int getLayoutId() {
        return R.layout.aty_home;
    }

    @Override
    public void refreshState(Bundle Bundle) {
        super.refreshState(Bundle);
        mineFragment.refreshState();
        squareFgm.refreshState();
    }
}
